import com.carrent.CarRentApplication;
import com.carrent.sys.domain.User;
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = CarRentApplication.class)
@RunWith(SpringRunner.class)
public class SpringbootTest1 {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedisTemplate redisTemplate;
    @Test
    public void testSet() throws Exception {
        stringRedisTemplate.opsForValue().set("username", "zhangsan");
        Assert.assertEquals("zhangsan", stringRedisTemplate.opsForValue().get("username"));
        System.out.println(stringRedisTemplate.opsForValue().get("username"));
        User user=new User();
        user.setLoginname("hhhh");
        //修改key的序列化方式
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //修改String的序列化方式
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.opsForValue().set("user",user);

        System.out.println(redisTemplate.opsForValue().get("user"));
    }

}
